package com.doordu.soa.service.web.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.doordu.soa.service.comm.utils.HTTPUtils;
import com.doordu.soa.service.web.dto.OSSToken;
import org.apache.commons.lang3.StringUtils;

public class OSSUtils {
	private static String sso_token_url = "http://ddservice.doordu.com:8000/dds/aliyun/v1/oss/sts?sid=doordu_admin_upload";
	
	public static OSSToken getOSSToken(String url) throws Exception {
		String str = "";
		if(StringUtils.isNotEmpty(url)){
			str = HTTPUtils.get(url+"/dds/aliyun/v1/oss/sts?sid=doordu_admin_upload");
		}else{
			str = HTTPUtils.get(sso_token_url);
		}
		
		JSONObject result = JSON.parseObject(str);
		OSSToken token = result.getObject("data", OSSToken.class);

		return token;
	}
}
